home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / fingerd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-10  |  5.4 KB  |  213 lines

  1. /* Internet Finger server */
  2. /* Mods by KO4KS */
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "global.h"
  6. #include "files.h"
  7. #include "mbuf.h"
  8. #include "socket.h"
  9. #include "session.h"
  10. #include "proc.h"
  11. #include "dirutil.h"
  12. #include "commands.h"
  13. #include "mailbox.h"
  14.  
  15. extern int ShowConfUsers __ARGS((int s));
  16. extern int Sconv;
  17. extern int Sftp;    /* Prototype socket for service */
  18. extern int BbsUsers, FtpUsers;
  19. #ifdef SCREENSAVER
  20. extern int Tutored;
  21. #endif
  22.  
  23. static int Sfinger = -1;    /* Prototype socket for service */
  24. static void fingerd __ARGS((int s,void *unused,void *p));
  25. extern int dombusers __ARGS((int argc,char *argv[],void *p));
  26. extern int dombmailstats __ARGS((int argc,char *argv[],void *p));
  27.  
  28. extern int cb_lookup __ARGS((int, char *, FILE *));
  29.  
  30.  
  31. /* Start up finger service */
  32. int
  33. finstart(argc,argv,p)
  34. int argc;
  35. char *argv[];
  36. void *p;
  37. {
  38.     return (installserver (argc, argv, &Sfinger, "Finger listener", IPPORT_FINGER,
  39.         "fingerd", fingerd, 1024, NULL));
  40. }
  41.  
  42. #define FLINE 128
  43.  
  44. static void
  45. fingerd(s,unused,p)
  46. int s;
  47. void *unused;
  48. void *p;
  49. {
  50. char user[80];
  51. int ulen,found;
  52. FILE *fp;
  53. char *file,*cp;
  54. char line[FLINE+1];
  55. int doconf = 0, dobbs = 0;
  56. #ifdef USERLOG
  57. int outsave;
  58. char *newargv[2];
  59. #endif
  60.  
  61.     sockmode(s,SOCK_ASCII);
  62.     sockowner(s,Curproc);
  63.     log(s,"open Finger");
  64.     recvline(s,user,80);
  65.     rip(user);
  66.     ulen = strlen(user);
  67.     if (ulen)    {
  68. #ifdef MSDOS
  69.         if (!strcmp (user, "con") || !strcmp (user, "aux"))    {
  70.             usprintf (s, "Can't finger '%s'... DOS Reserved Device Name\n", user);
  71.         close_s(s);
  72.         log(s,"close Finger");
  73.         return;
  74.     }
  75. #endif
  76. #ifdef CONVERS
  77.         if (!stricmp (user, "conf") || !stricmp (user, "stat"))
  78.             doconf = 1;
  79. #endif
  80.         if (!stricmp (user, "bbs") || !stricmp (user, "stat"))
  81.             dobbs = 1;
  82.     }
  83.     if(ulen && !strcmp(user,"iheard")) {
  84.     outsave = Curproc->output;
  85.     Curproc->output = s;
  86.     doipheard(0,NULL,NULL);
  87.     Curproc->output = outsave;
  88.     } else if (doconf || dobbs)    {
  89.     usprintf (s, "Current Status at %s\n\n", Hostname);
  90.         if (dobbs)    {
  91.             if (!BbsUsers)
  92.             usputs (s, "No users currently on the BBS\n");
  93.         else if (Listusers != NULL)    {
  94.                 usputs (s, "Bulletin Board ");
  95.             (*Listusers)(s);
  96.         }
  97. #ifdef CONVERS
  98.         if (doconf && dobbs)    {
  99. #else
  100.         if (dobbs)    {
  101. #endif
  102.             if (Sftp == -1)
  103.                 usprintf (s, "\nFTP Server not started\n");
  104.             else
  105.                 usprintf (s, "\nThere are %d in FTP Sessions\n", FtpUsers);
  106. #ifdef TUTOR
  107.             usprintf (s, "There are %d in Information Server Sessions\n", Tutored);
  108. #endif
  109.             usputs (s, "\n");
  110.         }
  111.         if (dobbs)    {
  112.             outsave = Curproc->output;
  113.             Curproc->output = s;
  114.             dombmailstats(0,NULLCHARP,NULL);
  115.             Curproc->output = outsave;
  116.         }
  117.     }
  118. #ifdef CONVERS
  119.     if (doconf)    {
  120.         if(Sconv == -1)
  121.             usputs(s,"Conference not started\n");
  122.         else    {
  123.             usputs (s, "Conference Bridge Users:\n");
  124.             ShowConfUsers(s);
  125.         }
  126.     }
  127. #endif
  128.         
  129.     } else {
  130.         if(ulen == 0){
  131.             char buffer[128];
  132.             sprintf (buffer, "%s/*.", Fdir);
  133.             fp = dir(buffer,0);
  134.             if(fp == NULLFILE)
  135.                 usprintf(s,"No finger information available\n");
  136.             else
  137.                 usprintf(s,"Known users on this system:\n");
  138.         } else {
  139. #ifdef SAMCALLB
  140.     cb_lookup (s, user, (FILE *) 0);
  141. #endif
  142. #ifdef USERLOG
  143.             outsave = Curproc->output;
  144.             Curproc->output = s;
  145.             newargv[1] = user;
  146.             dombuserinfo(0,newargv,NULL);
  147.             Curproc->output = outsave;
  148. #endif
  149.             file = pathname(Fdir,user);
  150.             cp = pathname(Fdir,"");
  151.             /* Check for attempted security violation (e.g., somebody
  152.              * might be trying to finger "../ftpusers"!)
  153.              */
  154.             if(strncmp(file,cp,strlen(cp)) != 0){
  155.                 fp = NULLFILE;
  156.                 usprintf(s,"Invalid user name %s\n",user);
  157.             } else if((fp = fopen(file,READ_TEXT)) == NULLFILE)    {
  158.                 /* Now search the finger database file for this user - WG7J */
  159.                 found = 0;
  160.                 if((fp = fopen(Fdbase,READ_TEXT)) != NULLFILE) {
  161.                     while(fgets(line,FLINE,fp) != NULLCHAR)
  162.                         if(!strnicmp(line,user,ulen)) {
  163.                             usprintf(s,"%s", line);
  164.                         while(fgets(line,FLINE,fp) != NULLCHAR)    {
  165.                             if (line[1] && *line != ' ' && *line != '\t')
  166.                                 break;
  167.                             else
  168.                                 usprintf (s, line);
  169.                         }
  170.                             found = 1;
  171.                             break;
  172.                         }
  173.                     fclose(fp);
  174.                     fp = NULLFILE;
  175.                 }
  176.                 if(!found)
  177.                     usprintf(s,"No user info for %s\n",user);
  178.             }
  179.             free(cp);
  180.             free(file);
  181.         }
  182.         if(fp != NULLFILE){
  183.             sendfile(fp,s,ASCII_TYPE,0);
  184.             fclose(fp);
  185.         }
  186. /* #ifdef CONVERS */
  187.     }
  188. /* #endif */
  189.     if(!ulen)    {
  190.         usputs (s, "\n*** Additional information available by fingering:\n");
  191. #ifdef CONVERS
  192.         usputs (s, "    stat, conf, bbs, or iheard\n");
  193. #else
  194.         usputs (s, "    stat, bbs, or iheard\n");
  195. #endif
  196.         if(Listusers != NULL)    {
  197.                 usputs (s, "\n");
  198.             (*Listusers)(s);
  199.         }
  200.     }
  201.     close_s(s);
  202.     log(s,"close Finger");
  203. }
  204. int
  205. fin0(argc,argv,p)
  206. int argc;
  207. char *argv[];
  208. void *p;
  209. {
  210.     return (deleteserver (&Sfinger));
  211. }
  212.  
  213.